package com.test.entities;

//import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;

//import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.sql.DataSource;

//import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

public class Manager {

	@Inject
//	@Named("pooledDS")
//	@Named("singleConnectionDataSource")
	@Named("driverManagerDataSource")
	private DataSource dataSource;
	
	@Inject
	@Named("jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	public Employee Manager;
	public List<Employee> directReports;
	public Properties properties;
	// @Resource(name="nograde")
	@Inject
	@Named("nograde")
	public String grade;

	public String getGrade() {
		return grade;
	}

	public void setGrade(String grade) {
		this.grade = grade;
	}

	public Properties getProperties() {
		return properties;
	}

	public void setProperties(Properties properties) {
		this.properties = properties;
	}

	public Employee getManager() {
		return Manager;
	}

	public Manager(Employee manager, List<Employee> directReports) {
		super();
		Manager = manager;
		this.directReports = directReports;
	}

	public Manager(Employee manager) {
		super();
		Manager = manager;
	}

	public void setManager(Employee manager) {
		Manager = manager;
	}

	public List<Employee> getDirectReports() {
		return directReports;
	}

	public void setDirectReports(List<Employee> directReports) {
		this.directReports = directReports;
	}

	public String accessDatabase() {
		/*
		 * try { Connection c = dataSource.getConnection();
		 * System.out.println("Connection Succesfull"); } catch(Exception e) {
		 * e.printStackTrace(); }
		 */
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		String query = "SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID=?";
		/**
		 * Implement the RowMapper callback interface
		 */
		return jdbcTemplate.queryForObject
				(
						query, 
						new Object[] { Manager.getEmployeeID() },
						new RowMapper<String>() 
						{
							public String mapRow(ResultSet resultSet, int rowNum) throws SQLException 
							{
								return resultSet.getString("FIRST_NAME");
							}
						}
				);

	}

}
